<template>
  <div class="works" :class="{ fold: fold }">
    <div class="g-clickable icon" @click="setFold">
      <img src="@/assets/creator/icon/icon-right.svg" />
    </div>
    <div class="list">
      <div class="item" v-for="(item, i) in list" :key="i">
        <img :src="item.image" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    list: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      fold: window.localStorage.getItem("works_fold") === "1",
    };
  },
  methods: {
    setFold() {
      this.fold = !this.fold;
      window.localStorage.setItem("works_fold", this.fold ? 1 : 0);
    },
  },
};
</script>

<style lang="scss" scoped>
.works {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  background-color: #14161a;

  &.fold {
    height: 10px;
    .list {
      display: none;
    }
    .icon {
      &:hover {
        top: -27px;
        height: 26px;
        img {
          transform: rotate(-90deg) scale(1.15);
        }
      }
      img {
        transform: rotate(-90deg);
      }
    }
  }

  .list {
    height: 150px;
    white-space: nowrap;
    overflow-x: auto;
    display: -webkit-box;
    overflow-x: scroll;
    -webkit-overflow-scrolling: touch;

    .item {
      width: 150px;
      height: 150px;

      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.3s ease;

      &:hover {
        background-color: rgba(255, 255, 255, 0.05);
      }

      img {
        width: 100px;
        height: 100px;
      }
    }
  }

  .icon {
    position: absolute;
    left: 50%;
    top: -25px;
    transform: translateX(-50%);
    background-color: #14161a;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-bottom: none;
    border-radius: 10px 10px 0 0;
    cursor: pointer;
    transition: all 0.3s ease;

    width: 80px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;

    &:hover {
      top: -27px;
      height: 26px;
      img {
        transform: rotate(90deg) scale(1.15);
      }
    }

    img {
      transform: rotate(90deg);
      transition: all 0.3s ease;
    }
  }
}
</style>
